package net.hnilica.cisteniulic.dao;

import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;
import org.apache.shiro.cache.CacheManager;

import org.apache.shiro.realm.jdbc.JdbcRealm;

/**
 * Sub-class of JdbcRealm that defines
 * the Data Source the JdbcRealm should
 * use
 * The configuration specified in web.xml
 * will cause an object of this class to 
 * be injected into the SecurityManager
 * @author brucephillips
 *
 */
public class RoleSecurityJdbcRealm extends JdbcRealm {

    private static final String authenticationQuery = "select heslo from osoba where email = ?";
    private static final String permissionsQuery = "select opravneni from role_opravneni where \"role\" = ?";
    private static final String userRolesQuery = "select \"role\" from osoba_role where email = ?";
  
    public RoleSecurityJdbcRealm() {

        super();
        setAuthenticationQuery(authenticationQuery);
        setPermissionsQuery(permissionsQuery);
        setUserRolesQuery(userRolesQuery);

        InitialContext ic;
        DataSource dataSource;
        try {

            
            ic = new InitialContext();
            dataSource = (DataSource) ic.lookup("java:/comp/env/jdbc/cistic");
            this.setDataSource(dataSource);

        } catch (NamingException e) {

            e.printStackTrace();

        }


    }

}
